<?php

namespace App\Model;

use App\User;
use Illuminate\Database\Eloquent\Model;

/**
 * Class UserDetail
 *
 * @package App\Model
 * @method static \Illuminate\Database\Query\Builder|$this create(array $attributes = [])
 * @method static \Illuminate\Database\Query\Builder|$this find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder|$this where($column, $operator = null, $value = null, $boolean = 'and')
 * @property-read \App\User $user
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail query()
 * @property int $id
 * @property int|null $user_id 用户id
 * @property string $name
 * @property string|null $wechat_name 用户名称（微信昵称）
 * @property string|null $open_id 唯一标识(openid.....)
 * @property string|null $union_id 微信唯一识别标识符
 * @property string|null $head_portrait 用户头像
 * @property string|null $local_head_portrait 本地头像
 * @property string|null $media_id 用户答题素材id
 * @property string|null $media_path 答题素材图片地址
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null $deleted_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereHeadPortrait($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereLocalHeadPortrait($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereMediaId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereMediaPath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereOpenId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereUnionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereWechatName($value)
 * @property int|null $subscribe 是否关注微信公众号0未关注1关注
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\UserDetail whereSubscribe($value)
 */
class UserDetail extends Model
{
    protected $table = 'user_detail';
    protected  $fillable = ['user_id', 'name', 'wechat_name', 'open_id', 'head_portrait', 'union_id'];

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }


    public static function head_portrait($id)
    {
        $detail =  UserDetail::where('user_id', $id)->first();
        return $detail['head_portrait'];
    }
}
